package com.lhf.aicloud.controller;

import com.lhf.aicloud.entity.Comment;
import com.lhf.aicloud.service.ICommentService;
import com.lhf.aicloud.utils.ResponseEntity;
import com.lhf.aicloud.utils.SecurityUtils;
import com.lhf.aicloud.utils.idempotent.Idempotent;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: lhf
 * @date: Created in 2024/08/13
 * @description:
 */
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Resource
    private ICommentService commentService;
    /**
     * 添加评论
     */
    @Idempotent
    @RequestMapping("/add")
    public ResponseEntity addComment(@Validated Comment comment) {
        comment.setUid(SecurityUtils.getCurrentUser().getUid());
        boolean result = commentService.save(comment);
        if (!result) {
            return ResponseEntity.error("添加评论失败");
        }

        return ResponseEntity.success("添加评论成功");
    }
}
